import go from 'gojs'

export function cdgInit(nodeDataArray, linkDataArray) {
	console.log(nodeDataArray, linkDataArray)
	var $ = go.GraphObject.make;  // for conciseness in defining templates
	var myDiagram =
		$(go.Diagram, "cdgDiagramDiv",  // must name or refer to the DIV HTML element
		{
		initialAutoScale: go.Diagram.Uniform,  // an initial automatic zoom-to-fit
		contentAlignment: go.Spot.Center,  // align document to the center of the viewport
		layout:
		$(go.TreeLayout,  // 垂直布局
		  { angle: 90, layerSpacing: 50 }) // 设置angle为90度，使布局垂直；layerSpacing用于设置垂直间距
	});
	// define each Node's appearance
	myDiagram.nodeTemplate =
		$(go.Node, "Auto",  // the whole node panel
		{ locationSpot: go.Spot.Center },
		// define the node's outer shape, which will surround the TextBlock
		$(go.Shape, "Rectangle",
		{ fill: $(go.Brush, "Linear", { 0: "rgb(254, 201, 0)", 1: "rgb(254, 162, 0)" }), stroke: "black" }),
		$(go.TextBlock,
		{ font: "bold 10px helvetica, bold arial, sans-serif", margin: 4 },
		new go.Binding("text", "label"))
		);
	// replace the default Link template in the linkTemplateMap
	myDiagram.linkTemplate =
		$(go.Link,  // the whole link panel
		$(go.Shape,  // the link shape
		{ stroke: "black" }),
		$(go.Shape,  // the arrowhead
		{ toArrow: "standard", stroke: null }),
		$(go.Panel, "Auto",
		$(go.Shape,  // the label background, which becomes transparent around the edges
		{
		fill: $(go.Brush, "Radial"),
		stroke: null
	}),
		$(go.TextBlock,  // the label text
		{
		textAlign: "center",
		font: "10pt helvetica, arial, sans-serif",
		stroke: "#555555",
		margin: 4
	},
		new go.Binding("text", "label"))
		),
		{
		fromSpot: go.Spot.Right, // 从右侧边缘衔接
		toSpot: go.Spot.Left,   // 到左侧边缘衔接
		// 如果连接到同一个节点，则设置连线之间的间距，以免重叠
		routing: go.Link.Orthogonal,
		corner: 5,
        }
    );
	myDiagram.model = new go.GraphLinksModel(nodeDataArray, linkDataArray);
    return myDiagram;
};